import request from '@/utils/request'

const path = '/platform/min_app/wechat_open/'

/** *********************微信服务商******************************************/

// 获取当前小程序模板信息
export function getOpenTemplate(platform_app_id) {
  return request({
    url: path + 'getOpenTemplate',
    method: 'post',
    data: { platform_app_id }
  })
}

// 获取授权地址
export function getPreAuthorizationUrl(platform_app_id) {
  return request({
    url: path + 'getPreAuthorizationUrl',
    method: 'post',
    data: { platform_app_id }
  })
}

export function getWechatAppInfo(platform_app_id) {
  return request({
    url: path + 'getWechatAppInfo',
    method: 'post',
    data: { platform_app_id }
  })
}

/**
 * 查询小程序版本信息
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getVersionInfo.html
 * @param {*} platform_app_id
 * @returns
 */
export function getVersionInfo(platform_app_id) {
  return request({
    url: path + 'getVersionInfo',
    method: 'post',
    data: { platform_app_id }
  })
}

/**
 * 查询最新一次审核单状态
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getLatestAuditStatus.html
 * @param {*} platform_app_id
 * @returns
 */
export function getLatestAuditStatus(platform_app_id) {
  return request({
    url: path + 'getLatestAuditStatus',
    method: 'post',
    data: { platform_app_id }
  })
}

// 代码提交
export function commit(platform_app_id, version = '1.0.0', desc = '版本提交') {
  return request({
    url: path + 'commit',
    method: 'post',
    data: { platform_app_id, version, desc }
  })
}

export function getCodePage(platform_app_id) {
  return request({
    url: path + 'getCodePage',
    method: 'post',
    data: { platform_app_id }
  })
}

export function getTrialQRCode(platform_app_id, appPath = '') {
  return request({
    url: path + 'getTrialQRCode',
    method: 'post',
    data: { platform_app_id, path: appPath }
  })
}

/**
 * 发布已通过审核的小程序
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/release.html
 * @param {*} platform_app_id
 * @returns
 */
export function release(platform_app_id) {
  return request({
    url: path + 'release',
    method: 'post',
    data: { platform_app_id }
  })
}

/**
 * 版本回滚|获取回滚版本
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/revertCodeRelease.html
 * @param {*} platform_app_id
 * @param {*} app_version 指定回滚版本号，填写后回滚到指定版本，不填则回滚到上一个版本
 * @param {*} get_history_version 是否获取历史版本号 0不获取 1获取
 * @returns
 */
export function revertCodeRelease(platform_app_id, app_version = '', get_history_version = 0) {
  return request({
    url: path + 'revertCodeRelease',
    method: 'post',
    data: { platform_app_id, app_version, get_history_version }
  })
}

/**
 * 查询小程序服务状态
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/getVisitStatus.html
 * @param {*} platform_app_id
 * @returns
 */
export function getVisitStatus(platform_app_id) {
  return request({
    url: path + 'getVisitStatus',
    method: 'post',
    data: { platform_app_id }
  })
}

/**
 * 设置小程序服务状态
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/setVisitStatus.html
 * @param {*} platform_app_id
 * @param {*} app_action 小程序服务状态，close 关闭服务，open 打开服务
 * @returns
 */
export function setVisitStatus(platform_app_id, app_action = 'close') {
  return request({
    url: path + 'setVisitStatus',
    method: 'post',
    data: { platform_app_id, app_action }
  })
}

/**
 * 提交代码审核
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/submitAudit.html
 * @param {*} platform_app_id
 * @param {*} version_desc
 * @returns
 */
export function submitAudit(platform_app_id, version_desc = '') {
  return request({
    url: path + 'submitAudit',
    method: 'post',
    data: { platform_app_id, version_desc }
  })
}

/**
 * 撤回审核
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/code-management/undoAudit.html
 * @param {*} platform_app_id
 * @returns
 */
export function undoAudit(platform_app_id) {
  return request({
    url: path + 'undoAudit',
    method: 'post',
    data: { platform_app_id }
  })
}

export function getAuditStatus(platform_app_id) {
  return request({
    url: path + 'setCodeAuditQuota',
    method: 'post',
    data: { platform_app_id }
  })
}

/**
 * 查询小程序隐私设置
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/privacy-management/getPrivacySetting.html
 * @param {*} platform_app_id
 * @param {*} privacy_ver 1表示现网版本，即，传1则该接口返回的内容是现网版本的；2表示开发版，即，传2则该接口返回的内容是开发版本的。默认是2
 * @returns
 */
export function getPrivacySetting(platform_app_id, privacy_ver = 1) {
  return request({
    url: path + 'getPrivacySetting',
    method: 'post',
    data: { platform_app_id, privacy_ver }
  })
}

/**
 * 配置小程序隐私设置
 * @document https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/privacy-management/setPrivacySetting.html
 * @param {*} platform_app_id
 * @param {*} owner_setting 开发者联系方式
 * @param {*} setting_list 要收集的用户信息配置
 * @returns
 */
export function setPrivacySetting(platform_app_id, owner_setting = {}, setting_list = []) {
  return request({
    url: path + 'setPrivacySetting',
    method: 'post',
    data: { platform_app_id, owner_setting, setting_list }
  })
}
